import React, {Component} from 'react';
import {
  View,
  Text,
  TouchableOpacity,
  StyleSheet,
  Platform,
  Picker,
  Image,
} from 'react-native';

import Config from '../../config';
import Colors from '../../common/Colors';
import CommonStyles from '../../common/CommonStyles';
import SizeUtils from '../../common/SizeUtils';
import TImage from '../../components/TImage';
import CommonListPage from '../common/CommonListPage';
import {DateUtils} from '../../utils/Utils';
import ToastUtils from '../../common/ToastUtils';
import Swipeout from 'react-native-swipeout';
import WH_RequestPostsAction from '../../actions/workhard/WH_RequestPostsAction';
import QZ_UncheckedList from '../../actions/quanzi/QZ_UncheckedList';
import QZ_CommentsUncheckedList from '../../actions/quanzi/QZ_CommentsUncheckedList';
import QZ_PostOrCommet from '../../actions/quanzi/QZ_PostOrCommet';

export default class QuanziReviewDataListView extends CommonListPage {
	   constructor(props) {
       super(props);
	   }
    componentWillUpdate(nextProps, nextState) {
        if(nextState.needRefresh ) {
          nextState.needRefresh = false;
          this.doRefresh();
          if(nextState.statusText != "") {
            ToastUtils.show(nextState.statusText);
            nextState.statusText = "";
          }
      }
    }
  	_getViewStyle() {
      return {paddingTop:0,
        backgroundColor:"#fff"}
    }
  	_getListViewStyle() {
      return {
        width:SizeUtils.getWindowSize().width,
        paddingTop:0,
        height:(SizeUtils.getWindowSize().height - Config.paddingTop),
        backgroundColor:"#fff"};
    }
    _postorcommetAction(data,ispass){
      new QZ_PostOrCommet().call(this, { status:ispass?1:3,
          target_id:this.props.type==='tiezi'?data.post_id:data.comment_id,target_type:this.props.type==='tiezi'?0:1 });
      
    }
    _onPressItem(data) {
      this.gotoPage(Config.pages.quanzi_post_content,data);
    }
    _onRenderItem(data, index) {
    	const swipeoutBtns = [
    	  {
  			backgroundColor:'#23a4ff',
    		text: '审核通过',
    		onPress:()=>{
          this._postorcommetAction(data,true)
    		}, 
  		  },
  		  {
  			backgroundColor:'#727272',
    		text: '审核不通过',
    		onPress:()=>{
          this._postorcommetAction(data,false)
    		}, 
  		  }
		];
      const isTiezi = this.props.type==='tiezi'?true:false;
    	return(
    	  <Swipeout autoClose={true} right={swipeoutBtns}>
  			<TouchableOpacity disabled={false} onPress={()=>{this._onPressItem(data)}} style={{
  				width:SizeUtils.getWindowSize().width,
  				backgroundColor:'#fff',
  				borderColor:'#eeeeee',
  				padding:SizeUtils.translateDesignWidthToCode(20),
        		borderBottomWidth:SizeUtils.translateDesignHeightToCode(3),
  			}}>
    			<Text style={{
            		fontSize:SizeUtils.translateFontSizeToCode(30),
            		backgroundColor:'#fff0',
            		color:'#000',
          		}}> {data.by_name||''} </Text>
          		<Text numberOfLines={4} style={{
            		fontSize:SizeUtils.translateFontSizeToCode(26),
            		backgroundColor:'#fff0',
            		paddingTop:SizeUtils.translateDesignWidthToCode(10),
            		paddingBottom:SizeUtils.translateDesignWidthToCode(10),
            		color:'#878787',
          		}}> {data.content.length>0?data.content:'暂无内容'} </Text>
          		<View style={{backgroundColor:'#f5f5f5'}}>
  				  {/*<Text style={{
  				  	paddingLeft:SizeUtils.translateDesignWidthToCode(10),
            		fontSize:SizeUtils.translateFontSizeToCode(26),
            		height:SizeUtils.translateDesignHeightToCode(40),
            		lineHeight:SizeUtils.translateDesignHeightToCode(40),
            		backgroundColor:'#fff0',
            		color:'#878787',
          		  }}><Text style={{color:'#fe7324'}}>{'泄露隐私信息:'}</Text> {'此人发布了太多隐私信息,予以举报'} </Text>*/}
  				</View>
  			</TouchableOpacity>
		  </Swipeout>
    	);
    }
    _requestData(page, listView) {
      if (this.props.type==='tiezi') {
        new QZ_UncheckedList().call(listView, {
        page:page, page_size:10,});
      }else{
        new QZ_CommentsUncheckedList().call(listView, {
        page:page, page_size:10});
      }
    }
}